const CACHE: {[key: string]: string} = {};
const CACHE_EXP: {[key: string]: Date} = {};

export const getCache = (key: string): string => {
    if (CACHE[key] != null && CACHE_EXP[key].getTime() > Date.now()) {
        return CACHE[key];
    }
    if (localStorage[key] != null && new Date(localStorage[key + '_exp']).getTime() > Date.now()) {
        return localStorage[key];
    }
    return null;
}
export const setCache = (key: string, value: string, exp: number = 1) => {
    CACHE[key] = value;
    const time = new Date();
    time.setMinutes(time.getMinutes() + exp);
    CACHE_EXP[key] = time;
    localStorage[key] = value;
    localStorage[key + '_exp'] = time;
}